<?php

use yii\db\Migration;

class m180908_123729_create_agent_package extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%agent_package}}', [
            'id' => $this->primaryKey(),
            'agent_id' => $this->integer()->notNull()->comment('代理商编号'),
            'package_id' => $this->integer()->notNull()->comment('套餐编号'),
            'cost_price' => $this->decimal(20, 4)->notNull()->comment('成本价'),
            'sale_price' => $this->decimal(20, 4)->notNull()->comment('销售价'),
        ]);
        $this->createIndex('fk_agent_package_agent1_idx', '{{%agent_package}}', ['agent_id']);
        try {
            $this->addForeignKey('fk_agent_package_agent1', '{{%agent_package}}', ['agent_id'], '{{%agent}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
        $this->createIndex('fk_agent_package_package1_idx', '{{%agent_package}}', ['package_id']);
        try {
            $this->addForeignKey('fk_agent_package_package1', '{{%agent_package}}', ['package_id'], '{{%package}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
    }

    public function safeDown()
    {
        $this->dropTable('{{%agent_package}}');
    }
}
